package com.ruoyi.modules.service.impl;

import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.modules.domain.YearJson;
import com.ruoyi.modules.mapper.YearJsonMapper;
import com.ruoyi.modules.service.YearJsonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class YearJsonServiceImpl implements YearJsonService {

    @Autowired
    private YearJsonMapper yearJsonMapper;

    @Override
    public List<YearJson> selectYearJsonList(YearJson yearJson) {
        return yearJsonMapper.selectYearJsonList(yearJson);
    }

    /**
     * 根据当前用户名获取已经贷款的年度，返回没有贷款的年度选项数组
     * @param userName
     * @return
     */
    @Override
    public List<YearJson> selectYearNotInAlreadyCreditYear(String userName) {
        return yearJsonMapper.selectYearNotInAlreadyCreditYear(userName);
    }

    @Override
    public YearJson selectYearJsonById(Long yearId) {
        return yearJsonMapper.selectYearJsonById(yearId);
    }

    @Override
    public int deleteYearJsonById(Long yearId) {
        return yearJsonMapper.deleteYearJsonById(yearId);
    }

    @Override
    public int deleteYearJsonByIds(Long[] yearIds) {
        int row = yearJsonMapper.deleteYearJsonByIds(yearIds);
        if (row > 0)
        {
            DictUtils.clearDictCache();
        }
        return row;
    }

    @Override
    public int insertYearJson(YearJson yearJson) {
        int row = yearJsonMapper.insertYearJson(yearJson);
        if (row > 0)
        {
            DictUtils.clearDictCache();
        }
        return row;
    }

    @Override
    public int updateYearJson(YearJson yearJson) {
        int row = yearJsonMapper.updateYearJson(yearJson);
        if (row > 0)
        {
            DictUtils.clearDictCache();
        }
        return row;
    }
}
